import { getColorTextLoadMap, tooltipLength } from '@/utils';
import pageStyles from '@/common/pageLayout.less';
import _ from 'lodash';
import { Tooltip } from 'antd';
import MyIcon from '@/components/MyIcon';

/** 排序 */
export const getSorter = (prev: Record<string, any>, next: Record<string, any>): number => (prev > next ? 1 : -1);

/** columns内容渲染的方法【文本】ColumnsRenderFun({ text }) */
export const ColumnsRenderFun = ({ text, isTooltip = false, textStyle = {}, event = undefined, record = {}, wordNum = 50 }: Record<string, any>) => {
  return (
    <>
      <Tooltip title={isTooltip ? tooltipLength(text, wordNum) : undefined}>
        <span className={pageStyles['over-flow-hidden']} onClick={event ? () => event(record) : undefined} style={textStyle}>
          {text == null || text == undefined || text == '' ? '--' : text}
        </span>
      </Tooltip>
    </>
  );
};

/** columns内容渲染的方法【字典】DictionaryRenderFun({ text }) */
export const DictionaryRenderFun = ({
  text,
  isTooltip = false,
  textStyle = {},
  event = undefined,
  record = {},
  wordNum = 50,
  isState = false,
}: Record<string, any>) => {
  const { colorText, color } = getColorTextLoadMap(text);
  return (
    <>
      <Tooltip title={isTooltip ? tooltipLength(text, wordNum) : undefined}>
        <span
          className={pageStyles['over-flow-hidden']}
          onClick={event ? () => event(record) : undefined}
          style={{ color: isState ? null : color, ...textStyle }}
        >
          {isState && text ? (
            <>
              <MyIcon type="icon-dian" style={{ color }} />
              &nbsp;
            </>
          ) : (
            <></>
          )}
          {colorText == null || colorText == undefined || colorText == '' ? '--' : colorText}
        </span>
      </Tooltip>
    </>
  );
};

/***
 * 操作类型
 * @param state
 * */
export const stateOfRendering = (state: string | number, isShowIcon: boolean = true) => {
  if (state == 0) {
    return (
      <div>
        <span>其他</span>
      </div>
    );
  } else if (state == 1) {
    return (
      <div>
        <span>查询</span>
      </div>
    );
  } else if (state == 2) {
    return (
      <div>
        <span>新增</span>
      </div>
    );
  } else if (state == 3) {
    return (
      <div>
        <span>修改</span>
      </div>
    );
  } else if (state == 4) {
    return (
      <div>
        <span>删除</span>
      </div>
    );
  } else if (state == 5) {
    return (
      <div>
        <span>授权</span>
      </div>
    );
  } else if (state == 6) {
    return (
      <div>
        <span>导出</span>
      </div>
    );
  } else if (state == 7) {
    return (
      <div>
        <span>导入</span>
      </div>
    );
  } else if (state == 8) {
    return (
      <div>
        <span>强退</span>
      </div>
    );
  } else if (state == 9) {
    return (
      <div>
        <span>生成代码</span>
      </div>
    );
  } else if (state == 10) {
    return (
      <div>
        <span>生成代码</span>
      </div>
    );
  } else {
    return (
      <div>
        <span>--</span>
      </div>
    );
  }
};

/***
 * 操作类型
 * @param state
 * */
export const businessTypeRendering = (state: string | number, isShowIcon: boolean = true) => {
  if (state == 0) {
    return '其他';
  } else if (state == 1) {
    return '查询';
  } else if (state == 2) {
    return '新增';
  } else if (state == 3) {
    return '修改';
  } else if (state == 4) {
    return '删除';
  } else if (state == 5) {
    return '授权';
  } else if (state == 6) {
    return '导出';
  } else if (state == 7) {
    return '导入';
  } else if (state == 8) {
    return '强退';
  } else if (state == 9) {
    return '生成代码';
  } else if (state == 10) {
    return '清空数据';
  }
};

/***
 * 操作状态
 * @param status
 * */
export const statusOfRendering = (state: string | number, isShowIcon: boolean = true) => {
  if (state == 0) {
    return (
      <div>
        <span>成功</span>
      </div>
    );
  } else if (state == 1) {
    return (
      <div>
        <span>异常</span>
      </div>
    );
  }
};

/***
 * 操作状态
 * @param status
 * */
export const statusTextOfRendering = (state: string | number, isShowIcon: boolean = true) => {
  if (state == 0) {
    return '成功';
  } else if (state == 1) {
    return '异常';
  }
};
